package com.ruoyi.web.controller.frontierCommand;

import java.util.List;
import java.util.Arrays;

import lombok.RequiredArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.frontierCommand.vo.TPatrolRecordVo;
import com.ruoyi.system.frontierCommand.bo.TPatrolRecordQueryBo;
import com.ruoyi.system.frontierCommand.bo.TPatrolRecordAddBo;
import com.ruoyi.system.frontierCommand.bo.TPatrolRecordEditBo;
import com.ruoyi.system.frontierCommand.service.ITPatrolRecordService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * 巡护记录Controller
 * 
 * @author ruoyi
 * @date 2021-05-20
 */
@Api(value = "巡护记录控制器", tags = {"巡护记录管理"})
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/frontierCommand/patrolRecord")
public class TPatrolRecordController extends BaseController {

    private final ITPatrolRecordService iTPatrolRecordService;

    /**
     * 查询巡护记录列表
     */
    @ApiOperation("查询巡护记录列表")
    @GetMapping("/list")
    public TableDataInfo<TPatrolRecordVo> list(TPatrolRecordQueryBo bo) {
        startPage();
        List<TPatrolRecordVo> list = iTPatrolRecordService.queryList(bo);
        return getDataTable(list);
    }

    /**
     * 根据巡护任务Id查询巡护记录列表
     */
    @ApiOperation("根据巡护任务Id查询巡护记录列表")
    @GetMapping("/queryRecordlistById")
    public TableDataInfo<TPatrolRecordVo> queryRecordlistById(TPatrolRecordQueryBo bo) {
        List<TPatrolRecordVo> list = iTPatrolRecordService.queryRecordlistById(bo);
        return getDataTable(list);
    }

    /**
     * 导出巡护记录列表
     */
    @ApiOperation("导出巡护记录列表")
    @PreAuthorize("@ss.hasPermi('frontierCommand:patrolRecord:export')")
    @Log(title = "巡护记录", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult<TPatrolRecordVo> export(TPatrolRecordQueryBo bo) {
        List<TPatrolRecordVo> list = iTPatrolRecordService.queryList(bo);
        ExcelUtil<TPatrolRecordVo> util = new ExcelUtil<TPatrolRecordVo>(TPatrolRecordVo.class);
        return util.exportExcel(list, "巡护记录");
    }

    /**
     * 获取巡护记录详细信息
     */
    @ApiOperation("获取巡护记录详细信息")
    @PreAuthorize("@ss.hasPermi('frontierCommand:patrolRecord:query')")
    @GetMapping("/{id}")
    public AjaxResult<TPatrolRecordVo> getInfo(@PathVariable("id" ) Long id) {
        return AjaxResult.success(iTPatrolRecordService.queryById(id));
    }

    /**
     * 新增巡护记录
     */
    @ApiOperation("新增巡护记录")
    @Log(title = "巡护记录", businessType = BusinessType.INSERT)
    @PostMapping()
    public AjaxResult<Void> add(@RequestBody TPatrolRecordAddBo bo) {
        return toAjax(iTPatrolRecordService.insertByAddBo(bo) ? 1 : 0);
    }

    /**
     * 修改巡护记录
     */
    @ApiOperation("修改巡护记录")
    @Log(title = "巡护记录", businessType = BusinessType.UPDATE)
    @PutMapping()
    public AjaxResult<Void> edit(@RequestBody TPatrolRecordEditBo bo) {
        return toAjax(iTPatrolRecordService.updateByEditBo(bo) ? 1 : 0);
    }

    /**
     * 删除巡护记录
     */
    @ApiOperation("删除巡护记录")
    @PreAuthorize("@ss.hasPermi('frontierCommand:patrolRecord:remove')")
    @Log(title = "巡护记录" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult<Void> remove(@PathVariable Long[] ids) {
        return toAjax(iTPatrolRecordService.deleteWithValidByIds(Arrays.asList(ids), true) ? 1 : 0);
    }
}
